package com.zz.ecommerce.assistSysManage.assistSys.service;

import com.zz.ecommerce.assistSysManage.assistSys.bean.TAssistSys;
import com.zz.ecommerce.assistSysManage.assistSys.bean.TAssistSysInter;
import com.zz.ecommerce.common.CommonDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zhangmeng on 2016/3/30.
 */
@Service
public class TAssistSysService {
    @Autowired
    CommonDao commonDao;

    /**
     * 保存辅助系统，如果存在sysId则更新，否则新增
     *
     * @param assistSys
     * @return
     */
    public String saveAssistSys(TAssistSys assistSys) {
        if (StringUtils.isEmpty(assistSys.getSysId())) {
            commonDao.insert("t_assist_sys", assistSys);
        } else {
            commonDao.update("t_assist_sys", assistSys, "where sys_id=#{updateObj.sysId}");
        }
        return "success";
    }

    /**
     * 保存接口信息，如果存在InterId则更新，否则新增
     *
     * @param assistSysInter
     * @return
     */
    public String saveAssistSysInter(TAssistSysInter assistSysInter) {
        if (StringUtils.isEmpty(assistSysInter.getInterId())) {
            commonDao.insert("t_assist_sys_inter", assistSysInter);
        } else {
            commonDao.update("t_assist_sys_inter", assistSysInter, "where inter_id=#{updateObj.interId}");
        }
        return "success";
    }

    /**
     * 删除辅助系统
     *
     * @param sysIds
     * @return
     */
    public String deleteTAssistSys(String sysIds) {
        if (StringUtils.isNotEmpty(sysIds)) {
            String ids[] = sysIds.split(",");
            for (String id : ids) {
                if (StringUtils.isNotEmpty(id)) {
                    commonDao.delete("t_assist_sys", " where sys_id=\'" + id + "\'");
                }
            }
        }
        return "success";
    }

    /**
     * 删除接口
     *
     * @param interIds
     * @return
     */
    public String deleteTAssistSysInter(String interIds) {
        if (StringUtils.isNotEmpty(interIds)) {
            String ids[] = interIds.split(",");
            for (String id : ids) {
                if (StringUtils.isNotEmpty(id)) {
                    commonDao.delete("t_assist_sys_inter", " where inter_id=\'" + id + "\'");
                }
            }
        }
        return "success";
    }
}
